from poco.drivers.android.uiautomation import AndroidUiautomationPoco
import subprocess
import time

class Model:
    def __init__(self):
        self.poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_method='maxtouch')


    def start_app(self):
        '''启动指定包名的应用'''
        package_name = 'com.tencent.apps.valorant'
        try:
            subprocess.run(['adb', 'shell', 'monkey', '-p', package_name, '-c', 
                            'android.intent.category.LAUNCHER', '1'], check=True)
            print(f"启动应用 {package_name} 成功。")
            time.sleep(1)
        except subprocess.CalledProcessError as e:
            print(f"启动应用时发生错误：{e}")


    def close_app(self):
        '''关闭指定包名的应用'''
        package_name = 'com.tencent.apps.valorant'
        try:
            # 关闭应用
            subprocess.run(['adb', 'shell', 'am', 'force-stop', package_name], check=True)
            print(f"关闭应用 {package_name} 成功。")
        except subprocess.CalledProcessError as e:
            print(f"关闭应用时发生错误：{e}")
